#!/bin/tcsh -ef
####
#
#############################################################################
#                                                                           #
# Title: Refine Merged Map                                                  #
#                                                                           #
# (C) 2dx.org, GNU Plublic License.                                         #
#                                                                           #
# Created..........: 21/01/2015                                             #
# Last Modification: 21/01/2015                                             #
# Author...........: Nikhil Biyani                                          #
#                                                                           #
#############################################################################
#
# SORTORDER: 89
#
# MANUAL: This script takes the unevenly spaced hkz file and generates a 3D reference map using backprojection.
#
#
# PUBLICATION: 3D reconstruction of two-dimensional crystals: <A HREF="http://www.ncbi.nlm.nih.gov/pubmed/26093179">Arch Biochem Biophys 581, 68-77 (2015)</A>
# PUBLICATION: 3D Reconstruction from 2D crystal image and diffraction data: <A HREF="http://dx.doi.org/10.1016/S0076-6879(10)82004-X">Methods Enzymol. 482, Chapter 4, 101-129 (2010)</A>
# PUBLICATION: 2dx - Automated 3D structure reconstruction from 2D crystal data: <A HREF="http://journals.cambridge.org/action/displayAbstract?aid=1943200">Microscopy and Microanalysis 14(Suppl. 2), 1290-1291 (2008)</A>
# PUBLICATION: 2dx_merge - Data management and merging for 2D crystal images: <A HREF="http://dx.doi.org/10.1016/j.jsb.2007.09.011">J. Struct. Biol. 160(3), 375-384 (2007)</A>
# PUBLICATION: Automatic Recovery of Missing Amplitudes and Phases in Tilt-Limited Electron Crystallography of 2D Crystals: <A HREF="http://link.aps.org/doi/10.1103/PhysRevE.84.011916">Phys. Rev. E Stat. Nonlin. Soft Matter Phys., Vol 84(1-1):011916 (2011)</A>
#
# DISPLAY: SYM
# DISPLAY: realcell
# DISPLAY: realang
# DISPLAY: ALAT
# DISPLAY: number_refinement_iterations
# DISPLAY: density_threshold_refinement_higher
# DISPLAY: density_threshold_refinement_lower
# DISPLAY: RESMIN
# DISPLAY: RESMAX
# DISPLAY: calculate_subvolume
# DISPLAY: refinement_mask_resolution
# DISPLAY: refinement_amplitude_cutoff
# DISPLAY: refinement_cone_angle
# DISPLAY: membrane_height
# DISPLAY: refinement_cone_energy_scale
#
#$end_local_vars
#
set bin_2dx = ""
set proc_2dx = ""
#
set SYM = ""
set realcell = ""
set realang = ""
set ALAT = ""
set RESMIN = ""
set RESMAX = ""
set calculate_subvolume = ""
set number_refinement_iterations = ""
set number_shrinkwrap_iterations = ""
set membrane_height = ""
set maximum_amplitude_refinement = ""
set density_threshold_refinement_higher = ""
set density_threshold_refinement_lower = ""
set refinement_mask_resolution = ""
set refinement_amplitude_cutoff = ""
set refinement_cone_angle = ""
set refinement_cone_energy_scale = ""
#
#$end_vars
#
set scriptname = 2dx_refineMergeMap
#
set split = ($realcell:as/,/ /)
set cellx = $split[1]
set celly = $split[2]
#
echo "cellx = ${cellx}"
echo "celly = ${celly}"
echo "cellz = ${ALAT}"
#
set cellxm1 = `echo ${cellx} | awk '{ s = $1 - 1 } END {print s}'`
set cellym1 = `echo ${celly} | awk '{ s = $1 - 1 } END {print s}'`
set ALATm1 = `echo ${ALAT} | awk '{ s = $1 - 1 } END {print s}'`
#
set date = `date`
echo date = ${date}
#
\rm -f LOGS/${scriptname}.results
#
set ccp4_setup = 'y'
source ${proc_2dx}/initialize
#
echo "<<@progress: 5>"
#
#############################################################################
${proc_2dx}/linblock "Sourcing ${proc_2dx}/2dx_refineMergedMap_sub.com"
#############################################################################
#
source ${proc_2dx}/2dx_refineMergedMap_sub.com
#
#############################################################################
${proc_2dx}/linblock "${scriptname} normal end."
#############################################################################
#
echo "<<@progress: 100>>"
#
exit
#
# These are here only to make sure they show up in the GUI:
source ${proc_2dx}/2dx_hkl_to_mtz.com
source ${proc_2dx}/2dx_extend_map.com
source ${proc_2dx}/2dx_create_subvolume.com
#
